package com.softa.common.sysconfig.support;

import lombok.Data;

/**
 *
 * @author yangl
 * @date 2018/5/15
 */
@Data
public class Result{

    private Integer code;

    /**
     * 自定义code
     */
    private Integer msgCode;

    private String message;

    private Object data;

    public Result() {}

    public Result(String message) {
        this.message = message;
    }

    public Result(String message, Object data) {
        this.message = message;
        this.data = data;
    }

    public Result(Integer code, Integer msgCode, String message) {
        this.code = code;
        this.msgCode = msgCode;
        this.message = message;
    }


    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result toSucess(){
        return new Result(HttpCode.OK.value(), "request sucess");
    }

    public static Result toFail(){
        return new Result(HttpCode.INTERNAL_SERVER_ERROR.value(), "request fail");
    }

    public static Result toSucess(Integer msgCode){
        Result result = toSucess();
        result.setMsgCode(msgCode);
        return result;
    }

    public static Result toSucess(Integer msgCode, String message){
        Result result = toSucess();
        result.setMsgCode(msgCode);
        result.setMessage(message);
        return result;
    }

}
